package p100;

import java.util.Stack;

public class Leetcode_165 {
    public int compareVersion(String version1, String version2) {
        String[] ss1 = version1.split("\\.");
        String[] ss2 = version2.split("\\.");
        Stack<Integer> stack1 = new Stack<>();
        Stack<Integer> stack2 = new Stack<>();
        for (int i = Math.max(ss1.length, ss2.length) - 1; i >= 0; i--) {
            if (i < ss1.length) {
                stack1.push(isEmpty(ss1[i]) ? 0 : Integer.parseInt(ss1[i]));
            } else {
                stack1.push(0);
            }
            if (i < ss2.length) {
                stack2.push(isEmpty(ss2[i]) ? 0 : Integer.parseInt(ss2[i]));
            } else {
                stack2.push(0);
            }
        }
        while (!stack1.isEmpty() && !stack2.isEmpty()) {
            int i1 = stack1.pop();
            int i2 = stack2.pop();
            if (i1 > i2) {
                return 1;
            }
            if (i1 < i2) {
                return -1;
            }
        }
//        while (!stack1.isEmpty()) {
//            if (stack1.pop() > 0) {
//                return 1;
//            }
//        }
//        while (!stack2.isEmpty()) {
//            if (stack2.pop() > 0) {
//                return -1;
//            }
//        }
        return 0;
    }

    public boolean isEmpty(String s) {
        return s == null || s.length() == 0;
    }

    public static void main(String[] args) {
        System.out.println(new Leetcode_165().compareVersion("1.0.1", "1.1"));
    }
}
